package com.aaa.gs.service;

import com.aaa.common.entity.Order;
import com.aaa.gs.mapper.ProductMapper;
import com.aaa.gs.po.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService{
    @Autowired
    private ProductMapper productMapper;

    //注入RestTemplate对象
    @Autowired
    private RestTemplate restTemplate;



    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Order> selectOrders() {
        //对HTTP和TCP客户端的行为进行大量控制
        //orderService 必须和要调用的服务的向注册中心注册应用名称一致
        // /order/selectAll 必须和调用服务中的方法请求的url一致
        return restTemplate.getForObject("http://orderService/order/selectAll",List.class);
    }
}
